package com.jihox.abookpro.util;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class RegexChk {

        private static boolean startCheck(String reg, String string) {
                boolean tem = false;
                Pattern pattern = Pattern.compile(reg);
                Matcher matcher = pattern.matcher(string);
                tem = matcher.matches();
                return tem;
        }

        /**
         * 手机号码验证,11位，不知道详细的手机号码段，只是验证开头必须是1和位数
         * */
        public static boolean checkCellPhone(String cellPhoneNr) {
                String reg = "^[1][\\d]{10}";
                return startCheck(reg, cellPhoneNr);
        }
        
        /**
         * 检查EMAIL地址 用户名和网站名称必须>=1位字符 地址结尾必须是2位以上，如：cn,test,com,info
         * */
        public static boolean checkEmail(String email) {
                String regex = "\\w+([-+.']\\w+)*@\\w+([-.]\\w+)*\\.\\w+([-.]\\w+)*";
                				
                return startCheck(regex, email);
        }

        /**
         * 检查邮政编码(中国),6位，第一位必须是非0开头，其他5位数字为0-9
         * */
        public static boolean checkPostcode(String postCode) {
                String regex = "^[1-9]\\d{5}";
                return startCheck(regex, postCode);
        }
}
